import ApiClient from '@/api/apiClient';

import type { RequestBody } from 'alova';

/**
 * 设备分组记录
 */
export interface DeviceGroup {
  /**
   * 创建时间
   */
  createTime?: string;
  /**
   * 更新时间
   */
  updateTime?: string;
  /**
   * 设备数量
   */
  deviceCount?: number;
  /**
   * 设备分组名称
   */
  groupName?: string;
  /**
   * 设备分组主键ID
   */
  id?: number;
  /**
   * 设备分组描述
   */
  remark?: string;
  [property: string]: unknown;
}

/** 设备分组列表 */
export const deviceGroupListApi = (data: RequestBody) => {
  return ApiClient.Post<API.ListType<DeviceGroup>>('/manager/deviceGroup/page', data, {
    meta: { auth: true },
  });
};
/** 删除设备分组 */
export const deviceGroupDeleteApi = (data: RequestBody) => {
  return ApiClient.Post('/manager/deviceGroup/batchRemoveById', data, {
    meta: { auth: true },
  });
};

/** 把设备从分组中移除 */
export const deviceGroupRemoveApi = (data: RequestBody) => {
  return ApiClient.Post('/manager/deviceGroup/removeGroup', data, {
    meta: { auth: true },
  });
};

/** 添加设备到分组 */
export const deviceGroupAddApi = (data: RequestBody & { groupId: string }) => {
  return ApiClient.Post(`/manager/deviceGroup/addGroup/${data.groupId}`, data, {
    meta: { auth: true },
  });
};

/**保存设备分组 */
export const deviceGroupSaveApi = (data: RequestBody) => {
  return ApiClient.Post<DeviceGroup>('/manager/deviceGroup/save', data, {
    meta: { auth: true },
  });
};

/** 获取设备分组详情 */
export const deviceGroupDetailApi = (data: { id: number }) => {
  return ApiClient.Get<DeviceGroup>(`/manager/deviceGroup/detail/${data.id}`, {
    meta: { auth: true },
  });
};
